package com.example.contact.view

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.contact.viewmodel.ContactViewModel
import com.example.featuresdk.R
import com.example.featuresdk.core.AbstractFeatureSDK
import com.example.featuresdk.view.FullScreen
import com.example.featuresdk.view.HeaderBackFeatureEntry
import com.example.featuresdk.view.FeatureEntry
import com.example.featuresdk.viewmodel.NavigationViewModel

@Composable
fun ContactDetailScreen(
    contactKey:String?,
    navigationViewModel: NavigationViewModel,
    featureSDK: AbstractFeatureSDK,
    contactViewModel: ContactViewModel = viewModel()){

    FullScreen(navigationViewModel){

        ContactDetailScreenHeader(navigationViewModel)

        ContactDetailView(contactKey,navigationViewModel, featureSDK, contactViewModel)
    }
}

@Composable
inline fun ContactDetailView(
    contactKey:String?,
    navigationViewModel: NavigationViewModel,
    featureSDK: AbstractFeatureSDK,
    contactViewModel: ContactViewModel = viewModel()
) {
    Text(text = "Contact = $contactKey")
}

@Composable
inline fun ContactDetailScreenHeader(navigationViewModel: NavigationViewModel){
    Row (modifier = Modifier
        .height(navigationViewModel.appHeaderBarHeightDp.dp)
        .background(Color.LightGray)
        .fillMaxWidth(),
        verticalAlignment = Alignment.CenterVertically){

        HeaderBackFeatureEntry(navigationViewModel)

        Spacer(modifier = Modifier.width((navigationViewModel.screenWithDp - navigationViewModel.headerIconSizeDp * 2).dp))

        FeatureEntry(R.drawable.ic_edit, onClick = {
            navigationViewModel.navHostController.navigate("contact/edit"){
                launchSingleTop = true
            }
        })
    }
}